package com.koocloud.electroplatemanage.controller;

import com.koocloud.electroplatemanage.common.pojo.ResponseTemplate;
import com.koocloud.electroplatemanage.pojo.ProductionPlan;
import com.koocloud.electroplatemanage.pojo.ProductionTask;
import com.koocloud.electroplatemanage.service.ProductionPlanService;
import com.koocloud.electroplatemanage.service.ProductionTaskService;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: Information_platform
 * @description: 生产任务单控制层
 * @author: xxc
 * @create: 2020-11-05 14:48
 */
@RestController
@RequestMapping("/productiontask")
public class ProductionTaskController {
    static Logger log = Logger.getLogger("productiontask");

    @Autowired
    ProductionTaskService productionTaskService;


    /**
     *@Description: 全表查询
     *@Param:
     *@return:
     *@Author: xxc
     *@date: 2020/11/5
     */
    @RequestMapping(value = "/selectAllData", method = RequestMethod.POST, name = "全表查询")
    public ResponseTemplate selectAllData(String page, String limit,String beginTime,String endTime, ProductionTask productionTask) {
        //分页参数为空则赋值0
        if (!StringUtils.isNotEmpty(page)) {
            page = "0";
        }
        if (!StringUtils.isNotEmpty(limit)) {
            limit = "0";
        }
        //查询所有记录 分页
        return productionTaskService.selectAllData(page,limit,beginTime,endTime,productionTask);

    }
    @RequestMapping(value = "/selectDataByWorkOrderNumber", method = RequestMethod.POST, name = "通过工单号查询生产计划数据")
    public ResponseTemplate selectDataByWorkOrderNumber(@RequestBody ProductionTask productionTask) {
        //查询所有记录 分页
        return productionTaskService.selectDataByWorkOrderNumber(productionTask);

    }


    /**
     *@Description: 新增一条数据
     *@Param: [request, productionTask]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/5
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST, name = "新增一条数据")
    public ResponseTemplate insert(HttpServletRequest request, @RequestBody ProductionTask productionTask) {
        String userId = request.getHeader("userId");
        //插入一条记录
        return productionTaskService.insert(productionTask,userId);

    }
    /**
     *@Description: 删除一条数据
     *@Param: [id]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/5
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST, name = "逻辑删除一条记录")
    public ResponseTemplate delete(HttpServletRequest request,@RequestParam(name="id") String id) {
        String userId = request.getHeader("userId");
        //逻辑删除一条记录
        return productionTaskService.delete(id,userId);

    }

    /**
     *@Description: 修改一条记录
     *@Param: [productionPlan]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/2
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST, name = "修改一条记录")
    public ResponseTemplate update(HttpServletRequest request,@RequestBody ProductionTask productionTask) {
        String userId = request.getHeader("userId");
        //修改一条记录
        return productionTaskService.update(productionTask,userId);
    }

    /**
     *@Description: 判断当前任务单是否需要拆分
     *@Param: [workOrderNumber, taskQuantity]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/19
     */
    @RequestMapping(value = "/inspectTasksNum", method = RequestMethod.POST, name = "判断当前任务单是否需要拆分")
    public ResponseTemplate inspectTasksNum(@RequestBody ProductionTask productionTask) {
        //判断当前任务单是否需要拆分
        return productionTaskService.inspectTasksNum(productionTask.getWorkOrderNumber(),productionTask.getTaskQuantity());
    }

    /**
     *@Description: 任务单确认
     *@Param: [workOrderNumber]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/19
     */
    @RequestMapping(value = "/confirmEntryInfo", method = RequestMethod.POST, name = "任务单确认")
    public ResponseTemplate confirmEntryInfo(HttpServletRequest request,String workOrderNumber){
        String userId = request.getHeader("userId");
        return productionTaskService.confirmEntryInfo(workOrderNumber,userId);

    }

}
